import { Component, ViewChild } from '@angular/core';
import { NavParams, Events, AlertController, App, ModalController, NavController, Content, ActionSheetController } from 'ionic-angular';
import { Storage } from '@ionic/storage';
import { Config } from '../../../providers/config';
import { DomSanitizer } from '@angular/platform-browser';
import _ from 'lodash';

import { Common } from "../../../providers/common";
import {BcwHomeService} from "./home.service";
import {BcwHomeDetailPage} from "./detail.component";

@Component({
  selector: 'page-bcw-home-list',
  templateUrl: './list.html',
  providers: [BcwHomeService]
})
export class BcwHomeListPage {
	moa_page_name: any = "page-bcw-home-list";
  moa_page_explain: any = "异常列表";

  returnData = null;
  dataList = [];

  selectRule = "";

  constructor(
    public alertCtrl: AlertController,
    public app: App,
    public modalCtrl: ModalController,
    public navCtrl: NavController,
    public config: Config,
    private sanitizer: DomSanitizer,
    public events: Events,
    public storage: Storage,
    private common: Common,
    private actionSheetCtrl: ActionSheetController,
    private bcwHomeService: BcwHomeService,
    private navParams: NavParams
  ) {
    this.loadDatas();
  }

  loadDatas() {
    let l_days = this.navParams.get("l_days");
    let vc_memo = this.navParams.get("vc_memo");
    this.bcwHomeService.getExceptionRuleDetail(l_days, vc_memo).subscribe(returnData => {
      console.log("getExceptionRuleDetail", returnData);
      if (returnData) {
        this.returnData = returnData;
        this.selectRule = this.returnData.rule[0];
        this.dataList = this.returnData.data[this.selectRule];
      }
    });
  }

  viewDetail(ruleName) {
    this.navCtrl.push(BcwHomeDetailPage, {
      dataList: this.returnData.data[ruleName]
    });
  }

  selectRuleChange() {
    this.dataList = this.returnData.data[this.selectRule];
  }
}
